iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 25
0
自我挑戰組

30天教你學會Git系列 第 25

[Day25] 今天要來上點甚麼課呢!!!

  • 分享至 

  • xImage
  •  

啊。我好像沒有講刪除檔案餒~

  • 我們來看看如果刪除檔案的時候會發生什麼事情吧!
$ ls
Helloworld.txt  README.md

$ rm Helloworld.txt && ls
README.md
  • OK,我們刪除了一個檔案了嘛,那來看看狀態吧
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    Helloworld.txt

no changes added to commit (use "git add" and/or "git commit -a")
  • 現在呢~Git追蹤到你刪除了一個檔案,下一步要幹嘛勒?!
  • 就是跟新增檔案一樣,要使用git add,把東西給增加到暫存區(Staging Area)裡面
  • 你可以把它想成,你要更改暫存區裡面的內容啦~
$ git add .

$ git commit -m "Delete Doc Helloworld"
$ git commit -m "Delete doc Helloworld"
[master 55cf8d6] Delete doc Helloworld
 1 file changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 Helloworld.txt
  • 如果你覺得以上很麻煩~我教你一個更快的方法
  • 一樣先回到那個狀況
$ ls
Helloworld.txt  README.md

$ git status
On branch master
Your branch is ahead of 'origin/master' by 3 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

  • 接下來,請使用git rm XXXXX
$ git rm Helloworld.txt
rm 'Helloworld.txt'

$ git status
On branch master
Your branch is ahead of 'origin/master' by 3 commits.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        deleted:    Helloworld.txt

  • 咦!這樣就完成了餒XD
  • 快很多吧!!

跟剛剛有關係的....

  • 想起來,還有一個叫做改檔名
  • 如果我們今天要把檔名從Helloworld.txt 換成 Byeworld.txt
  • 你可以這樣做....
$ ls
Helloworld.txt  README.md

$ mv Helloworld.txt Byeworld.txt

$ ls
Byeworld.txt  README.md

$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    Helloworld.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        Byeworld.txt

no changes added to commit (use "git add" and/or "git commit -a")

$ git add .

$ git commit -m "Del Helloworld & Add Byeworld"
[master 16e1d92] Del Helloworld & Add Byeworld
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename Helloworld.txt => Byeworld.txt (100%)
  • 覺得會太麻煩嗎?
  • 那我們用快點吧XD
$ ls
Helloworld.txt  README.md

$ git mv Helloworld.txt Byeworld.txt

$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        renamed:    Helloworld.txt -> Byeworld.txt

$ git add .

$ git commit -m "Del Helloworld & Add Byeworld"
[master e9d6fe7] Del Helloworld & Add Byeworld
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename Helloworld.txt => Byeworld.txt (100%)
  • 這樣你就達到一樣的效果啦~

明天我們在繼續看別的狀況啦~


上一篇
[Day24] 我們昨天說得好像...有點意思
下一篇
[Day26] 之前的學生問了一個很棒的問題....
系列文
30天教你學會Git30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言